#!/usr/bin/env python
#-*- coding:UTF-8 -*-
import os, sys, filetype, re, urllib

folder = input('请输入文件夹路径:')
errorfiles = []
def isMp4Codding(file):
 kind = filetype.guess(file)
 if kind is None:
     print('错误文件:'+ file)
     errorfiles.append(file)
     return
 if kind.mime != "video/mp4":
     print('错误mp4:'+ file + 'file mime:',kind.mime)

def traverse(f):  
    fs = os.listdir(f)  
    for f1 in fs:  
        tmp_path = os.path.join(f,f1)  
        if not os.path.isdir(tmp_path): 
            if file_extension(tmp_path).find('mp4') != -1 or file_extension(tmp_path).find('MP4') != -1:
            	isMp4Codding(tmp_path)
        else:  
            traverse(tmp_path)  
def file_extension(path):
 	return os.path.splitext(path)[1]
def savefile(content,filepath):
	file = open(filepath,'w')
	file.write('\n'.join(content))
	file.close()
if __name__ == '__main__':
 	traverse(folder)
 	if len(errorfiles) > 0:
 		filepath = os.path.join(folder, '错误视频列表.txt')
 		savefile(errorfiles,filepath)

